package com.ostrich.a2104gao5

/**
 * @Author : yaotianxue
 * @Time : On 2023/10/13 15:06
 * @Description : Test3
 */
fun main(){
    //lambda表达式==匿名函数，{}
    //高阶函数:参数或返回值为函数类型的函数叫做高阶函数
    val printUserChinese = { username:String,age:Int ->
        "姓名=$username 年龄=$age"
    }
    val printUserEnglish = {username:String,age:Int->
        "name=$username age=$age"
    }
    //将匿名函数作为参数传入
    println(show("yaotianxue",12,printUserChinese))
    println(show("yaotianxue",12,printUserEnglish))

    //简写
    println(show("yaotianxue",13,{ username:String,age:Int ->
        "姓名=$username 年龄=$age"
    }))
    //最终简写
    println(show("yaotianxue",14){username:String,age:Int ->
        "姓名=$username 年龄=$age"
    })
    //5。温故it
    var countL = "helloll".count {
        it == 'l'
    }
    println(countL)
}


//printUser：参数名称  (String,Int)->String：参数类型是函数 输入参数是String,Int，输出参数是String
fun show(username:String,age:Int,printUser:(String,Int)->String):String{
    return printUser(username,age)
}
